
using System.Collections.Generic;
using System.Text.RegularExpressions;
/// <summary>
/// 语言包分类
/// </summary>
public enum enHFLanguageClassify
{
        /// <summary>
        /// 简体中文[CN]
        /// </summary>
        [HFAliasTooltip("简体中文[CN]")]
        CN = 0,
}
/// <summary>
/// 语言包根目录
/// </summary>
public enum enHFLanguageRootFolder
{
    /// <summary>
    /// Unknown
    /// </summary>      
    Unknown,
        /// <summary>
        /// Assets/Game/GameHFResource
        /// </summary>       
        ASSETS_GAME_GAMEHFRESOURCE,
}
/// <summary>
/// 语言包帮助类
/// </summary>
public static partial class HFLanguageHelper
{
    /// <summary>
    /// 语言包
    /// </summary>
    public static readonly enHFLanguageClassify defaultAlternateLanguage = enHFLanguageClassify.CN;    
    /// <summary>
    /// 语言包
    /// </summary>
    public static enHFLanguageClassify language { get; private set; } = enHFLanguageClassify.CN;
    /// <summary>
    /// Db库语言包索引
    /// </summary>
    public static int langIndex { get { return (int)language; } }
    /// <summary>
    /// 变更语言包
    /// </summary>
    /// <param name="_lan">语言包</param>
    public static void ChangeLanguage(enHFLanguageClassify _lan)
    {
        language = _lan;
    }
    /// <summary>
    /// AB资源根路径
    /// </summary>
    static Dictionary<enHFLanguageRootFolder, Dictionary<enHFLanguageClassify,string>> mAbRootPathMaping = 
        new Dictionary<enHFLanguageRootFolder, Dictionary<enHFLanguageClassify, string>>()
    {
        
             {
                enHFLanguageRootFolder.ASSETS_GAME_GAMEHFRESOURCE,
                new Dictionary<enHFLanguageClassify, string>{
                    
                        { enHFLanguageClassify.CN,"Assets/Game/GameHFResource/CN"},
                                        
                }
            },               
        
            
    };
    /// <summary>
    /// Root路径
    /// </summary>
    static Dictionary<enHFLanguageRootFolder, string> mAbRootFolderMaping = new Dictionary<enHFLanguageRootFolder, string>()
    {
        
                {enHFLanguageRootFolder.ASSETS_GAME_GAMEHFRESOURCE,"Assets/Game/GameHFResource"},
                
    };
    /// <summary>
    /// 获得AB资源根目录
    /// </summary>
    /// <param name="_rootFolder">根路径</param>
    /// <returns>AB资源根目录</returns>
    public static string GetRootFolder(enHFLanguageRootFolder _rootFolder)
    {
        return mAbRootFolderMaping.ContainsKey(_rootFolder) ? mAbRootFolderMaping[_rootFolder] : string.Empty;
    }
    /// <summary>
    /// 获得AB资源根目录
    /// </summary>
    /// <param name="_rootFolder">根路径</param>
    /// <param name="_lang">语言</param>
    /// <returns>AB资源根目录</returns>
    public static string GetAssetBundleRootPath(enHFLanguageRootFolder _rootFolder, enHFLanguageClassify _lang)
    {
        return mAbRootFolderMaping.ContainsKey(_rootFolder) ? mAbRootPathMaping[_rootFolder][_lang] : string.Empty;
    }
    /// <summary>
    /// 解析路径
    /// </summary>
    /// <param name="_path">路径</param>
    /// <param name="_rootFolder">enHFLanguageRootFolder</param>
    /// <param name="_relativePath">相对路径</param>
    /// <returns>true:解析成功,false:解析失败</returns>
    public static bool ResolvePath(string _path, out enHFLanguageRootFolder _rootFolder, out string _relativePath)
    { 
        bool result = false;
        _rootFolder = 0;
        _relativePath = _path;
        bool hasRootFolder = false;
        foreach (var key in mAbRootFolderMaping)
        {
            if (_path.ToLower().StartsWith(key.Value.ToLower()))
            {
                _rootFolder = key.Key;
                _relativePath = Regex.Replace(_path, key.Value, "", RegexOptions.IgnoreCase).HFForceRelativePath();
                hasRootFolder = true;
                break;
            }
        }
        if (hasRootFolder)
        {
            var lanp = mAbRootPathMaping[_rootFolder];
            foreach (var key in lanp)
            {
                if (_path.ToLower().StartsWith(key.Value.ToLower()))
                {
                    _relativePath = Regex.Replace(_path, key.Value, "", RegexOptions.IgnoreCase).HFForceRelativePath();
                    result = true;
                    break;
                }
            }
        }
        return result;
    }
}
